<template>
    <div>
        <van-nav-bar title="商品详情" left-text="返回" left-arrow @click-left="() => { $router.push('/') }" fixed />
        <div style="height: 45px;"></div>
        <van-swipe :autoplay="3000" lazy-render>
            <van-swipe-item v-for="image in images" :key="image">
                <img :src="image" style="width: 350px;" />
            </van-swipe-item>
        </van-swipe>
        <div v-html="detail.goods_introduce"></div>
        <van-action-bar>
            <van-action-bar-icon icon="chat-o" text="客服" color="#ee0a24" />
            <van-action-bar-icon icon="cart-o" text="购物车" />
            <van-action-bar-icon icon="star" text="已收藏" color="#ff5000" />
            <van-action-bar-button type="warning" text="加入购物车" @click="addCart" />
            <van-action-bar-button type="danger" text="立即购买" />
        </van-action-bar>
        <van-skeleton title :row="3" />
    </div>
</template>

<script setup>
import { detailApi } from '@/api/api';
import { ref } from 'vue';
import { useRoute } from 'vue-router';
const route = useRoute()
let detail = ref([])
detailApi(route.params.goods_id).then(res => {
    console.log('详情数据', res);
    detail.value = res.data.message
})
const images = [
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg',
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg',
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-3.jpeg',
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-4.jpeg',
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-5.jpeg',
];
import { useCounterStore } from '@/stores/piniaCart'
import router from '@/router';
// 在组件内部的任何地方均可以访问变量 `store` ✨
const store = useCounterStore()
const addCart=()=>{
    store.piniaCart=store.value,route.params.goods_id
    router.push('/home/cart')
}
</script>

<style lang="scss" scoped></style>